<template>
  <div>
    <a-row :gutter='10'>
      <a-col :md='4' :sm='24'>
        <a-card :bordered='false'>
          <div style='background: #fff;padding-left:6px;height: 100%; margin-top: 5px'>
            <a-tree
              showLine
              :selectedKeys='selectedKeys'
              :checkStrictly='true'
              @select='onSelect'
              :dropdownStyle="{maxHeight:'200px',overflow:'auto'}"
              :treeData='departTree'
              :autoExpandParent='autoExpandParent'
              :expandedKeys='iExpandedKeys'
              @expand='onExpand'
            />
          </div>
        </a-card>
      </a-col>
      <a-col :md='20' :sm='24'>
        <a-card :bordered='false'>
          <!-- 查询区域 11111-->
          <div class='table-page-search-wrapper'>
                  <a-form layout='inline' :label-col='labelCol' @keyup.enter.native='searchQuery'>
                    <a-row :gutter='24'>
                      <a-col :md='8' :sm='8'>
                        <a-form-item label='服务名称'>
                          <a-input placeholder='请输入服务名称' v-model='queryParam.project'></a-input>
                        </a-form-item>
                      </a-col>
                      <span style='float: left;overflow: hidden;' class='table-page-search-submitButtons'>
                         <a-col :md='6' :sm='24'>
                             <a-button type='primary' @click='searchQuery' icon='search'>查询</a-button>
                             <a-button type='primary' @click='searchReset' icon='reload' style='margin-left: 8px'>重置</a-button>
                         </a-col>
                      </span>
              </a-row>
            </a-form>
          </div>

          <!-- 操作按钮区域 -->
          <div class='table-operator' :md='24' :sm='24'>
            <a-button @click='handleAdd' type='primary' icon='plus' style='margin-top: 16px'>新增服务项目</a-button>
          </div>

          <!-- table区域-begin -->
          <div>
            <a-table
              ref='table'
              size='middle'
              bordered
              rowKey='id'
              :scroll='{x:1300}'
              :columns='columns'
              :dataSource='dataSource'
              :pagination='ipagination'
              :loading='loading'
              @change='handleTableChange'>

              <template slot='imgSlot' slot-scope='text'>
                <span v-if='!text' style='font-size: 12px;font-style: italic;'>无图片</span>
                <img v-else :src='getImgView(text)' height='30px' alt=''
                     style='max-width:80px;font-size: 12px;font-style: italic;' />
              </template>
              <span slot='action' slot-scope='text, record'>
                <a @click='handleEdit(record)' v-if="record.tenantId>0">编辑</a>
                <a-divider type='vertical' v-if="record.tenantId>0"/>
                <a-dropdown v-if="record.tenantId>0">
                  <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
                      <a-menu slot='overlay'>
                            <a-menu-item>
                              <a-popconfirm title='确定删除吗?' @confirm='() => handleDelete(record.id)'>
                                <a>删除</a>
                              </a-popconfirm>
                            </a-menu-item>
                      </a-menu>
                </a-dropdown>
              </span>

            </a-table>
          </div>
        </a-card>
      </a-col>
    </a-row>
    <HChDoorServiceProject-modal ref='modalForm' @ok='modalFormOk'></HChDoorServiceProject-modal>
    <HisCategory-modal ref='modalFormCategory' @ok='modalFormOk'></HisCategory-modal>
  </div>

</template>
<script>
import '@assets/less/TableExpand.less'
import HChDoorServiceProjectModal from '../../modules/HChDoorServiceProjectModal'
import HisCategoryModal from '../../modules/HisCategoryModal'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { putAction, getAction, postAction, deleteAction } from '@api/manage'
import { frozenBatch, queryMyNurseCategoryTreeList, searchByKeywords } from '@api/api'

export default {
  name: 'h_his_nurse_service_projectList',
  mixins: [JeecgListMixin],
  components: {
    HChDoorServiceProjectModal,
    HisCategoryModal
  },
  data() {
    return {
      description: '护理服务项目管理页面',
      labelCol: { style: { width: '90px' } },
      queryParam: {
        //3上门护理 4上门照护 5陪诊服务 6慢性康复 7营养指导  10慢性
        projectType: '6'
      },
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '项目分类',
          align: 'center',
          dataIndex: 'categoryName'
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'project'
        },
        {
          title: '项目主图片',
          align: 'center',
          dataIndex: 'img',
          scopedSlots: { customRender: 'imgSlot' }
        },
        {
          title: '项目费用(RMB)',
          align: 'center',
          dataIndex: 'amount'
        },
        {
          title: '销售数量',
          align: 'center',
          dataIndex: 'saleQty',
          customRender: function(t, r, index) {
            return t==0?"暂无":t;
          }
        },
        {
          title: '服务评分',
          align: 'center',
          dataIndex: 'score',
          customRender: function(t, r, index) {
            return t==0?"暂无":t;
          }
        },
        {
          title: '项目服务时间(次/分)',
          align: 'center',
          dataIndex: 'time'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        categoryDetele: '/his/common/category',
        categoryList: '/his/common/category/selectList',
        list: '/ch/door/project/list',
        delete: '/his/material'
      },
      iExpandedKeys: [],
      loading: false,
      autoExpandParent: true,
      disable: true,
      treeData: [],
      departTree: [],
      visible: false,
      hiding: true,
      model: {},
      depart: {},
      checkedKeys: [],
      selectedKeys: [],
      currentDeptId: 0
    }
  },
  computed: {},
  created() {
    this.refresh()
  },
  methods: {
    callback(key) {
      //console.log(key)
    },
    clearSelectedDepartKeys() {
      this.checkedKeys = []
      this.selectedKeys = []
      this.currentDeptId = ''
      this.$refs.DeptUserInfo.currentDeptId = ''
    },
    loadTree() {
      var that = this
      that.treeData = []
      that.departTree = []
      getAction(this.url.categoryList, { categoryType: '6' }).then((res) => {
        if (res.success && res.result) {
          for (let i = 0; i < res.result.length; i++) {
            let temp = res.result[i]
            that.treeData.push(temp)
            that.departTree.push(temp)
            that.setThisExpandedKeys(temp)
          }
          this.loading = false
        }
      })
    },
    setThisExpandedKeys(node) {
      //只展开一级目录
      if (node.children && node.children.length > 0) {
        this.iExpandedKeys.push(node.key)
      }
    },
    refresh() {
      this.loading = true
      this.loadTree()
    },

    onExpand(expandedKeys) {
      this.iExpandedKeys = expandedKeys
      this.autoExpandParent = false
    },
    onCheck(checkedKeys, e) {
      let record = e.node.dataRef
      // console.log('onCheck', checkedKeys, e);
      this.checkedKeys = []
      // if (e.checked === true) {
      this.currentDeptId = record.id
      this.checkedKeys.push(record.id)
      this.hiding = false
    },
    onSelect(selectedKeys, e) {
      if (this.selectedKeys[0] !== selectedKeys[0]) {
        this.selectedKeys = [selectedKeys[0]]
      }
      let record = e.node.dataRef
      this.checkedKeys.push(record.id)
      this.currentDeptId = record.id

      this.queryParam.categoryId=record.id
      this.loadData()
    },
    handleAdd: function() {
      this.$refs.modalForm.add('6', '6')
      this.$refs.modalForm.title = '新增'
      this.$refs.modalForm.disableSubmit = false
    },
    handleEdit: function (record) {
      this.$refs.modalForm.edit(record,'6');
      this.$refs.modalForm.title = "编辑";
      this.$refs.modalForm.disableSubmit = false;
    },
    handleTime() {
      this.$router.push({ path: '/family/doortime' })
    },
    modalFormOk() {
      this.loadTree()
      // 新增/修改 成功时，重载列表
      this.loadData()
      //清空列表选中
      this.onClearSelected()
    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>